package com.tdam2014.grupo3.flickr;

import com.tdam2014.grupo3.flickr.interfaces.CommentInterface;
import com.tdam2014.grupo3.flickr.interfaces.PeopleInterface;
import com.tdam2014.grupo3.flickr.interfaces.PhotoInterface;
import com.tdam2014.grupo3.flickr.interfaces.PhotoSetInterface;

/**
 * Main entry point for the Flickr API.
 * This class is used to acquire Interface classes which wrap the Flickr API.
 *
 * @author Anthony Eden, adapted by Lucas Cunibertti for Flickr Viewer.
 */
public class Flickr {
	
    public static final String DEFAULT_API_HOST = "api.flickr.com";

    private String apiKey;
    private Transport transport;
    
    private CommentInterface commentInterface;
    private PeopleInterface peopleInterface;
    private PhotoInterface photoInterface;
    private PhotoSetInterface photoSetInterface;

    /**
     * Construct a new Flickr gateway instance. Defaults to a REST transport.
     *
     * @param apiKey The API key, must be non-null
     */
    public Flickr(String apiKey) {
        setApiKey(apiKey);
        setTransport(new REST(DEFAULT_API_HOST));
    }

    /**
     * Construct a new Flickr gateway instance.
     *
     * @param apiKey The API key, must be non-null
     * @param transport The transport (REST or SOAP), must be non-null
     */
    public Flickr(String apiKey, Transport transport) {
        setApiKey(apiKey);
        setTransport(transport);
    }
    
    public String getApiKey() {
        return apiKey;
    }
    
    public void setApiKey(String apiKey) {
        if (apiKey == null) {
            throw new IllegalArgumentException("API key must not be null.");
        }
        this.apiKey = apiKey;
    }
    
    public Transport getTransport() {
        return transport;
    }
    
    public void setTransport(Transport transport) {
        if (transport == null) {
            throw new IllegalArgumentException("Transport must not be null");
        }
        this.transport = transport;
    }
    
    public CommentInterface getCommentInterface() {
        if (commentInterface == null) {
            commentInterface = new CommentInterface(apiKey, transport);
        }
        return commentInterface;
    }

    public PeopleInterface getPeopleInterface() {
        if (peopleInterface == null) {
            peopleInterface = new PeopleInterface(apiKey, transport);
        }
        return peopleInterface;
    }

    public PhotoInterface getPhotoInterface() {
        if (photoInterface == null) {
            photoInterface = new PhotoInterface(apiKey, transport);
        }
        return photoInterface;
    }

    public PhotoSetInterface getPhotoSetInterface() {
        if (photoSetInterface == null) {
            photoSetInterface = new PhotoSetInterface(apiKey, transport);
        }
        return photoSetInterface;
    }
}
